package entities;

import java.awt.Image;

import javax.swing.ImageIcon;

import logic.Utilities;

/** The Bat's class for the brick breaker game.
 * @author Team 1
 *
 */
@SuppressWarnings("serial")
public class Bat extends MovableEntity{
	
	private boolean canShoot = false;		//The can shoot flag.
	private int ammo = 0;					//The remaining ammunition.
	private ImageIcon icon;					//The ImageIcon of the label.
	
	/** Bat's constructor, without initial movement and without ammo.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 * Obviously if the scales are equals to one it doesn't resize.
	 */
	public Bat(int x, int y, float xScale, float yScale) {
		super(x, y);
		Image image = Utilities.loadImage("res/bat.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/bat.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
	}
	
	/** Bat's constructor, without initial movement but with ammo.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 * Obviously if the scales are equals to one it doesn't resize.
	 * @param ammo : the value of the remaining ammunition.
	 */
	public Bat(int x, int y, float xScale, float yScale, int ammo) {
		super(x, y);
		Image image = Utilities.loadImage("res/bat.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/bat.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		if(ammo < 999) {
			this.ammo = ammo;
		} else {
			this.ammo = 999;
		}
		if(this.ammo > 0)
		{
			canShoot = true;
		} else {
			canShoot = false;
		}
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
	}
	
	/** Bat's constructor, with initial movement but without ammo.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param dx : the horizontal speed.
	 * @param dy : the vertical speed. 
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 * Obviously if the scales are equals to one it doesn't resize.
	 */
	public Bat(int x, int y, int dx, int dy, float xScale, float yScale) {
		super(x, y, dx, dy);
		Image image = Utilities.loadImage("res/bat.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/bat.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
	}
	
	/** Bat's constructor, with initial movement and with ammo.
	 * @param x : the entity's upper-left corner's x coordinate.
	 * @param y : the entity's upper-left corner's y coordinate.
	 * @param dx : the horizontal speed.
	 * @param dy : the vertical speed. 
	 * @param xScale : the x resize scale. If it's lower than one it reduces the images original width, increase it otherwise.
	 * @param yScale : the y resize scale. If it's lower than one it reduces the images original height, increase it otherwise.
	 * Obviously if the scales are equals to one it doesn't resize.
	 * @param ammo : the value of the remaining ammunition.
	 */
	public Bat(int x, int y, int dx, int dy, float xScale, float yScale, int ammo) {
		super(x, y, dx, dy);
		Image image = Utilities.loadImage("res/bat.png");
		if(xScale != 1 || yScale != 1) {
			image = Utilities.resizeImage(xScale, yScale, "res/bat.png");
		}
		icon = new ImageIcon(image);
		this.setIcon(icon);
		if(ammo < 999) {
			this.ammo = ammo;
		} else {
			this.ammo = 999;
		}
		if(this.ammo > 0)
		{
			canShoot = true;
		} else {
			canShoot = false;
		}
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
	}

	/** Returns if the bat can shoot or not.
	 * @return canShoot 
	 */
	public boolean getCanShoot() {
		return canShoot;
	}
	
	/** Sets bat's ammo number. If the ammo given is zero makes bat unable to shoot by setting false canShoot.
	 * @param ammo : number of the ammo given.
	 */
	public void setAmmo(int ammo) {
		if(ammo < 999) {
			this.ammo = ammo;
		} else {
			this.ammo = 999;
		}
		if(this.ammo > 0)
		{
			canShoot = true;
		} else {
			canShoot = false;
		}
	}
	
	/** Returns bat's ammo.
	 * @return ammo : bat's remaining ammunition.
	 */
	public int getAmmo() {
		return ammo;
	}
	
	public void resize(float xScale, float yScale) {
		super.resize(xScale, yScale);
		this.icon = new ImageIcon(Utilities.resizeImage(xScale, yScale, "res/bat.png"));
		this.setIcon(icon);
	}
	
	/** Return the bat's width for all resolution giving the windows width divided by 1280.
	 * @param xScale : The windows horizontal proportion value.
	 * @return The value of the ball's width depending on the horizontal scale.
	 */
	public static int getWidth(float xScale) {
		return Math.round(90 * xScale);
	}
	
	/**Return the bat's height for all resolution giving the windows height divided by 720.
	 * @param yScale : The windows vertical proportion value.
	 * @return The value of the ball's height depending on the vertical scale.
	 */
	public static int getHeight(float yScale) {
		return Math.round(18 * yScale);
	}
}